package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

public class B2d
{
	private static BodyFactoryPool _bodyFactoryPool;
	private static CircleFactoryPool _circleFactoryPool;
	private static PolygonFactoryPool _polygonFactoryPool;
	private static BoxFactoryPool _boxFactoryPool;
	private static EdgeFactoryPool _edgeFactoryPool;
	private static ChainFactoryPool _chainFactoryPool;
	
	private static RopeJointFactoryPool _ropeJointFactoryPool;
	private static DistanceJointFactoryPool _distanceJointFactoryPool;
	private static RevoluteJointFactoryPool _revoluteJointFactoryPool;
	private static PulleyJointFactoryPool _pulleyJointFactoryPool;
	private static WheelJointFactoryPool _wheelJointFactoryPool;
	private static FrictionJointFactoryPool _frictionJointFactoryPool;
	private static GearJointFactoryPool _gearJointFactoryPool;
	private static MouseJointFactoryPool _mouseJointFactoryPool;
	private static PrismaticJointFactoryPool _prismaticJointFactoryPool;
	private static WeldJointFactoryPool _weldJointFactoryPool;
	
//	public static cleanup()
//	{
//		if(_bodyFactoryPool != null)
//			_bodyFactoryPool.clear();
//	}
	
	public static BodyFactory dynamicBody()
	{
		return bodyFactory().type(BodyType.DynamicBody);
	}
	
	public static BodyFactory staticBody()
	{
		return bodyFactory().type(BodyType.StaticBody);
	}
	
	public static BodyFactory kinematicBody()
	{
		return bodyFactory().type(BodyType.KinematicBody);
	}
	
	private static BodyFactory bodyFactory()
	{
		if(_bodyFactoryPool == null)
			_bodyFactoryPool = new BodyFactoryPool();
		BodyFactory f = _bodyFactoryPool.obtain();
		f.clear();
		return f;
	}

	public static CircleFactory circle()
	{
		if(_circleFactoryPool == null)
			_circleFactoryPool = new CircleFactoryPool();	
		CircleFactory f = _circleFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static PolygonFactory polygon(Vector2[] verts)
	{
		if(_polygonFactoryPool == null)
			_polygonFactoryPool = new PolygonFactoryPool();	
		PolygonFactory f = _polygonFactoryPool.obtain();
		f.clear();
		f.set(verts);
		return f;
	}
	
	public static BoxFactory box(float hw, float hh)
	{
		if(_boxFactoryPool == null)
			_boxFactoryPool = new BoxFactoryPool();	
		BoxFactory f = _boxFactoryPool.obtain();
		f.clear();
		f.size(hw, hh);
		return f;
	}
	
	public static EdgeFactory edge()
	{
		if(_edgeFactoryPool == null)
			_edgeFactoryPool = new EdgeFactoryPool();	
		EdgeFactory f = _edgeFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static ChainFactory chain()
	{
		if(_chainFactoryPool == null)
			_chainFactoryPool = new ChainFactoryPool();	
		ChainFactory f = _chainFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static ChainFactory chain(Vector2[] verts)
	{
		return chain().asLine(verts);
	}
	
	public static ChainFactory loop(Vector2[] verts)
	{
		return chain().asLoop(verts);
	}
	
	public static RopeJointFactory ropeJoint()
	{
		if(_ropeJointFactoryPool == null)
			_ropeJointFactoryPool = new RopeJointFactoryPool();	
		RopeJointFactory f = _ropeJointFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static DistanceJointFactory distanceJoint()
	{
		if(_distanceJointFactoryPool == null)
			_distanceJointFactoryPool = new DistanceJointFactoryPool();	
		DistanceJointFactory f = _distanceJointFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static RevoluteJointFactory revoluteJoint()
	{
		if(_revoluteJointFactoryPool == null)
			_revoluteJointFactoryPool = new RevoluteJointFactoryPool();	
		RevoluteJointFactory f = _revoluteJointFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static PulleyJointFactory pulleyJoint()
	{
		if(_pulleyJointFactoryPool == null)
			_pulleyJointFactoryPool = new PulleyJointFactoryPool();	
		PulleyJointFactory f = _pulleyJointFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static WheelJointFactory wheelJoint()
	{
		if(_wheelJointFactoryPool == null)
			_wheelJointFactoryPool = new WheelJointFactoryPool();	
		WheelJointFactory f = _wheelJointFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static FrictionJointFactory frictionJoint()
	{
		if(_frictionJointFactoryPool == null)
			_frictionJointFactoryPool = new FrictionJointFactoryPool();	
		FrictionJointFactory f = _frictionJointFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static GearJointFactory gearJoint()
	{
		if(_gearJointFactoryPool == null)
			_gearJointFactoryPool = new GearJointFactoryPool();	
		GearJointFactory f = _gearJointFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static MouseJointFactory mouseJoint()
	{
		if(_mouseJointFactoryPool == null)
			_mouseJointFactoryPool = new MouseJointFactoryPool();	
		MouseJointFactory f = _mouseJointFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static PrismaticJointFactory prismaticJoint()
	{
		if(_prismaticJointFactoryPool == null)
			_prismaticJointFactoryPool = new PrismaticJointFactoryPool();	
		PrismaticJointFactory f = _prismaticJointFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static WeldJointFactory weldJoint()
	{
		if(_weldJointFactoryPool == null)
			_weldJointFactoryPool = new WeldJointFactoryPool();	
		WeldJointFactory f = _weldJointFactoryPool.obtain();
		f.clear();
		return f;
	}
	
	public static void free(BodyFactory f)
	{
		_bodyFactoryPool.free(f);
	}
	
	public static void free(CircleFactory f)
	{
		_circleFactoryPool.free(f);
	}

	public static void free(BoxFactory boxFactory)
	{
		_boxFactoryPool.free(boxFactory);
	}

	public static void free(ChainFactory chainFactory)
	{
		_chainFactoryPool.free(chainFactory);
	}

	public static void free(EdgeFactory edgeFactory)
	{
		_edgeFactoryPool.free(edgeFactory);
	}

	public static void free(PolygonFactory polygonFactory)
	{
		_polygonFactoryPool.free(polygonFactory);
	}

	public static void free(DistanceJointFactory distanceJointFactory)
	{
		_distanceJointFactoryPool.free(distanceJointFactory);
	}

	public static void free(FrictionJointFactory frictionJointFactory)
	{
		_frictionJointFactoryPool.free(frictionJointFactory);
	}

	public static void free(GearJointFactory gearJointFactory)
	{
		_gearJointFactoryPool.free(gearJointFactory);
	}

	public static void free(MouseJointFactory mouseJointFactory)
	{
		_mouseJointFactoryPool.free(mouseJointFactory);
	}

	public static void free(PrismaticJointFactory prismaticJointFactory)
	{
		_prismaticJointFactoryPool.free(prismaticJointFactory);
	}

	public static void free(PulleyJointFactory pulleyJointFactory)
	{
		_pulleyJointFactoryPool.free(pulleyJointFactory);
	}

	public static void free(RevoluteJointFactory revoluteJointFactory)
	{
		_revoluteJointFactoryPool.free(revoluteJointFactory);
	}

	public static void free(RopeJointFactory ropeJointFactory)
	{
		_ropeJointFactoryPool.free(ropeJointFactory);
	}

	public static void free(WeldJointFactory weldJointFactory)
	{
		_weldJointFactoryPool.free(weldJointFactory);
	}

	public static void free(WheelJointFactory wheelJointFactory)
	{
		_wheelJointFactoryPool.free(wheelJointFactory);
	}
}
